/*
 * MainFrame for GUI interactivity.
 *
 * License: LGPL v3.
 *
 * Created on Sep 27, 2009, 11:33:00 AM
 */
package org.passwordstore.gui;

import java.awt.AWTException;
import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Image;
import java.awt.Insets;
import java.awt.Rectangle;
import java.awt.SystemTray;
import java.awt.TrayIcon;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.WindowEvent;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.Writer;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.Date;
import java.util.List;
import java.util.Properties;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.DefaultListModel;
import javax.swing.ImageIcon;
import javax.swing.JFileChooser;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPopupMenu;
import javax.swing.JTable;
import javax.swing.ListSelectionModel;
import javax.swing.RowSorter;
import javax.swing.SortOrder;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableModel;
import javax.swing.table.TableRowSorter;
import org.passwordstore.Resource;
import org.passwordstore.util.H2JDBCParser;
import org.passwordstore.util.Password;
import org.passwordstore.util.Restore;

/**
 *
 * @author thotheolh
 */
public class MainFrame extends javax.swing.JFrame {

    private Properties system;
    private DefaultTableModel model;
    private DefaultTableModel bkmodel;
    private DefaultListModel listmodel;
    private Password pass;
    private int tableRow = -1;
    private boolean isPopupShown = false;
    private boolean showPassword = false;
    private boolean miniOnClose = false;
    private boolean isSearchShown = false;
    private BufferedReader br;
    private TableRowSorter<TableModel> sorter;
    private Comparator<String> comparator;
    private Date date1, date2;
    private long l1, l2;
    private TrayIcon trayIcon;
    private BorderLayout contentLayout = null;
    private Image iconImg = null;
    private MainFrame mainFrame;
    private ArrayList<String> invisibleDialogs = null;
    private JMenuItem exitItem;
    private JMenuItem addPassItem;
    private JMenuItem restoreItem;
    private JMenuItem hidePopupItem;

    /** Creates new form MainFrame */
    public MainFrame() {
        initComponents();
        int width = 450; //444
        int height = 500;
        invisibleDialogs = new ArrayList<String>();
        setSize(width, height);
        mainFrame = this;
        setLocationRelativeTo(null);
        iconImg = this.getImageIcon("pwdstore.png");
        this.setIconImage(iconImg);
        addUniversalQuitBtn();
        init();
    }

    /**
     * Main init() method
     */
    public void init() {
        this.setDefaultCloseOperation(this.DO_NOTHING_ON_CLOSE); //When windowClosing is called, the frame is already closing... use this to prevent
        initWindow(); // Init the window design
        checkShowPass(); //Check if user enabled showing of password on the main table option
        initTrayIcon(); //Init System Tray
        initTableModel(); //Init Table Model
        initTableData(); //Init Table Data
        initBkTableModel(); //Init Backup File Table Model
        initBkFileTable(); //Init Backup File Table
        initSettingsPane(); //Init Settings Panel

        //Handle close window event
        addWindowListener(new java.awt.event.WindowAdapter() {

            @Override
            public void windowClosing(WindowEvent winEvt) {
                closeAppWindow();
            }

            @Override
            public void windowIconified(WindowEvent winEvt) {
                if (Resource.getInstance().getSystem().getProperty("gui.lockOnMin").equalsIgnoreCase("true")) {
                    doLockWindow();
                } else if (Resource.getInstance().getSystem().getProperty("gui.lockOnMin").equalsIgnoreCase("false")) {
                    // Do nothing.
                } else {
                    // Presume wrong setting. Set to default as false.
                    system = Resource.getInstance().getSystem();
                    system.setProperty("gui.lockOnMin", "false");
                    Resource.getInstance().setSystem(system);
                }
            }
        });
    }

    /**
     * Init Window design
     */
    public void initWindow() {
        //Init main window tabs
        initMainTabs();

        //Adjust look and feel
        if (Resource.getInstance().getSystem().getProperty("gui.pref").equals("swing")) {
            this.pack();
        }
    }

    /**
     * Init window tabs
     */
    public void initMainTabs() {
        //Init main window tabs
        mainTabPane.setTabPlacement(javax.swing.JTabbedPane.TOP);
    }

    /**
     * Init table model
     */
    public void initTableModel() {
        model = new MyDefaultTableModel();
        table.setModel(model);
        model.addColumn("Username");
        if (isShowPassword()) {
            model.addColumn("Password");
        }
        model.addColumn("Required Place");
        ListSelectionModel selectionModel = table.getSelectionModel();
        selectionModel.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        ListSelectionModel rowSM = table.getSelectionModel();
        cleanTable(table);
        table.getColumnModel().getColumn((model.getColumnCount() - 1)).setPreferredWidth(200);
    }

    /**
     * Init table data
     */
    public void initTableData() {
        int numrows = model.getRowCount();
        for (int i = numrows - 1; i >= 0; i--) {
            model.removeRow(i);
        }
        if (!isShowPassword()) {
            ArrayList aList = Resource.getInstance().getSql().viewAllPasswords();
            String[] row = new String[4];
            for (int i = 0; i < aList.size(); i++) {
                pass = (Password) aList.get(i);
                if (pass != null) {
                    row[0] = pass.getUname();
                    row[1] = pass.getRplace();
                    model.addRow(row);
                }
            }
        } else {
            ArrayList aList = Resource.getInstance().getSql().viewAllPasswordsWPass();
            String[] row = new String[4];
            for (int i = 0; i < aList.size(); i++) {
                pass = (Password) aList.get(i);
                if (pass != null) {
                    row[0] = pass.getUname();
                    row[1] = pass.getUpass();
                    row[2] = pass.getRplace();
                    model.addRow(row);
                }
            }
        }
        validate();
        repaint();
    }

    public void initBkTableModel() {
        bkmodel = new MyDefaultTableModel();
        bkFileTable.setModel(bkmodel);
        bkFileTable1.setModel(bkmodel);
        bkFileTable.setAutoCreateRowSorter(true);
        bkFileTable1.setAutoCreateRowSorter(true);
        bkmodel.addColumn("File");
        bkmodel.addColumn("Last Updated");
        //bkFileTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
        bkFileTable.getColumnModel().getColumn(0).setPreferredWidth(20);
        bkFileTable1.getColumnModel().getColumn(0).setPreferredWidth(20);
        ListSelectionModel selectionModel = bkFileTable.getSelectionModel();
        selectionModel.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        ListSelectionModel rowSM = bkFileTable.getSelectionModel();
        selectionModel = bkFileTable1.getSelectionModel();
        selectionModel.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        rowSM = bkFileTable1.getSelectionModel();
        sorter = new TableRowSorter<TableModel>(bkFileTable.getModel());
        bkFileTable.setRowSorter(sorter);
        comparator = new Comparator<String>() {

            @Override
            public int compare(String t1, String t2) {
                date1 = convertDate(t1, date1);
                date2 = convertDate(t2, date2);
                return date1.compareTo(date2);
            }
        };
        sorter.setComparator(1, comparator);
        List<RowSorter.SortKey> sortKeys = new ArrayList<RowSorter.SortKey>();
        sortKeys.add(new RowSorter.SortKey(1, SortOrder.ASCENDING));
        sorter.setSortKeys(sortKeys);
        cleanTable(bkFileTable);
        sorter = new TableRowSorter<TableModel>(bkFileTable1.getModel());
        bkFileTable1.setRowSorter(sorter);
        comparator = new Comparator<String>() {

            @Override
            public int compare(String t1, String t2) {
                date1 = convertDate(t1, date1);
                date2 = convertDate(t2, date2);
                return date1.compareTo(date2);
            }
        };
        sorter.setComparator(1, comparator);
        sortKeys = new ArrayList<RowSorter.SortKey>();
        sortKeys.add(new RowSorter.SortKey(1, SortOrder.ASCENDING));
        sorter.setSortKeys(sortKeys);
        bkFileTable1.removeAll();
    }

    public void initBkTableData(String[] data) {
        String[] row = new String[2];
        int numrows = bkmodel.getRowCount();
        for (int i = numrows - 1; i >= 0; i--) {
            bkmodel.removeRow(i);
        }
        for (int i = 0; i < data.length; i++) {
            row[0] = data[i].trim().toString();
            row[1] = getTimestampe(data[i].trim().toString());
            bkmodel.addRow(row);
        }
    }

    /**
     * Fetch a list of available backup file
     */
    public void initBkFileTable() {
        File file = new File("backup");
        if (file.exists()) {
            String[] fileList = file.list();
            initBkTableData(fileList);
        }
        repaint();
    }

    public void initTrayIcon() { //Init only if config specifies
        if (Resource.getInstance().getSystem().getProperty("gui.minOnClose").equalsIgnoreCase("true")) {
            setMiniOnClose(true);
            if (SystemTray.isSupported()) {

                SystemTray tray = SystemTray.getSystemTray();
                setTrayIcon(new TrayIcon(iconImg, "PasswordStore", null));

                //Popup
                final JPopupMenu jpopup = new JPopupMenu();

                //Menu Items
                exitItem = new JMenuItem("Exit");
                addPassItem = new JMenuItem("Add Password");
                restoreItem = new JMenuItem("Restore Window");
                hidePopupItem = new JMenuItem("Hide Popup");

                exitItem.addActionListener(new ActionListener() {

                    @Override
                    public void actionPerformed(ActionEvent e) {
                        quitApp();
                    }
                });

                addPassItem.addActionListener(new ActionListener() {

                    @Override
                    public void actionPerformed(ActionEvent e) {
                        restorePopup();
                        newBtnActionPerformed(e);
                    }
                });

                restoreItem.addActionListener(new ActionListener() {

                    @Override
                    public void actionPerformed(ActionEvent e) {
                        restorePopup();
                    }
                });

                hidePopupItem.addActionListener(new ActionListener() {

                    @Override
                    public void actionPerformed(ActionEvent e) {
                        jpopup.setVisible(false);
                        isPopupShown = false;
                    }
                });

                jpopup.add(hidePopupItem);
                jpopup.add(restoreItem);
                jpopup.addSeparator();
                jpopup.add(addPassItem);
                jpopup.addSeparator();
                jpopup.add(exitItem);

                getTrayIcon().addMouseListener(new MouseAdapter() {

                    @Override
                    public void mouseClicked(MouseEvent e) {

                        if (!isPopupShown) {
                            jpopup.setLocation(e.getX(), e.getY());
                            jpopup.setInvoker(jpopup);
                            jpopup.setVisible(true);
                            isPopupShown = true;
                        } else if (isPopupShown) {
                            jpopup.setVisible(false);
                            isPopupShown = false;
                        } else {
                        }
                    }
                });

                getTrayIcon().setImageAutoSize(true); //Tray Icon image auto resize

                try {
                    tray.add(getTrayIcon());
                } catch (AWTException e) {
                    System.err.println("Err - TrayIcon could not be added.");
                }
            }
        }
    }

    public void initSettingsPane() { //Inits settings panel
        String tmp = "";

        // Show password in table
        tmp = Resource.getInstance().getSystem().getProperty("gui.showpwd");
        if (tmp.equalsIgnoreCase("true")) {
            viewTable.setSelected(true);
        }

        // GUI LAF Preferences
        tmp = Resource.getInstance().getSystem().getProperty("gui.pref");
        if (tmp.equalsIgnoreCase("swing")) { //If pref is Swing

            lafCB.setSelectedItem("Swing");

        } else if (tmp.equalsIgnoreCase("a03")) { // If pref is A03

            lafCB.setSelectedItem("A03");

        } else { //A03 by default

            lafCB.setSelectedItem("A03");

        }

        // Minimize window upon close

        tmp = Resource.getInstance().getSystem().getProperty("gui.minOnClose");
        if (tmp.equalsIgnoreCase("true")) { // Allow min on close window

            minWindow.setSelected(true);

        }

        // Lockdown Window

        tmp = Resource.getInstance().getSystem().getProperty("gui.lockWin");
        if (tmp.equalsIgnoreCase("true")) {

            enableLock.setSelected(true);

        }

        // Time out to Lock Window

        tmp = Resource.getInstance().getSystem().getProperty("gui.lockMin");
        int timeout = 3; // 3 minutes of default time out timing.
        try {
            timeout = Integer.valueOf(tmp);
            if (timeout <= 0) {
                timeout = 3;
            }
        } catch (NumberFormatException ex) {
            Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, null, ex);
        }
        if (Resource.getInstance().getSystem().getProperty("gui.lockWin").equalsIgnoreCase("true")) { // If timer is enabled
            Resource.getInstance().startTimerInstance(timeout); //Start timer
        } else {
            Resource.getInstance().stopTimerInstance();
        }
        lockDownTF.setText("" + timeout);

        // Lock window when window is minimizsed

        tmp = Resource.getInstance().getSystem().getProperty("gui.lockOnMin");
        if (tmp.equalsIgnoreCase("true")) {
            lockOnMinCB.setSelected(true);
        } else if (tmp.equalsIgnoreCase("false")) {
            lockOnMinCB.setSelected(false);
        } else {
            // Presume wrong setting. Set to default as false.
            lockOnMinCB.setSelected(false);
            system = Resource.getInstance().getSystem();
            system.setProperty("gui.lockOnMin", "false");
            Resource.getInstance().setSystem(system);
        }

        // Default Database export format

        tmp = Resource.getInstance().getSystem().getProperty("sys.dbExport");
        if (tmp.equalsIgnoreCase("SQL")) {
            expFrmtCB.setSelectedItem("SQL");
        } else if (tmp.equalsIgnoreCase("CSV")) {
            expFrmtCB.setSelectedItem("CSV");
        } else {
            expFrmtCB.setSelectedItem("SQL");
        }

    }

    public void restorePopup() {
        if (Resource.getInstance().getMainInstance().isIsLocked()) {
            Resource.getInstance().getMainInstance().getLogin().setVisible(true);
        } else {
            this.setVisible(true);
        }
    }

    /**
     * Delete password information set
     * @param username
     * @param rqplace
     */
    private void deletePassword(String username, String rqplace) {
        int numOpt = JOptionPane.showConfirmDialog(this, "Are you sure you want to delete this password set ?", "Delete Password", JOptionPane.YES_NO_OPTION);
        if (numOpt == JOptionPane.YES_OPTION) {
            pass = new Password();
            pass.setUname(username);
            pass.setRplace(rqplace);
            if (Resource.getInstance().getSql().deletePassword(pass)) {
                JOptionPane.showMessageDialog(this, "Password have been successfully deleted.", "Pasword deleted", JOptionPane.INFORMATION_MESSAGE);
                initTableData();
            } else {
                JOptionPane.showMessageDialog(this, "Password delete have failed.", "Pasword delete failed", JOptionPane.ERROR_MESSAGE);
            }
        }
    }

    /**
     * Database restoration method
     * @param filename
     */
    private void doRestore(String filename) {
        Restore restore = new Restore(Resource.getInstance());
        int numRows = restore.doRestore(new File("backup/" + filename));
        if (numRows == 0) {
            JOptionPane.showMessageDialog(this, "There's nothing being restored.", "Nothing restored", JOptionPane.INFORMATION_MESSAGE);
        } else {
            JOptionPane.showMessageDialog(this, "Data have been restored.", "Data restored", JOptionPane.INFORMATION_MESSAGE);
        }
        this.initTableData();
    }

    /**
     * Show right click popup
     * @param evt
     */
    private void showPopup(MouseEvent evt) {
//        System.out.println("! - showPopup()");
        if (evt.isPopupTrigger()) {
//            System.out.println("Popup Triggered...");
            setTableRow(table.rowAtPoint(evt.getPoint()));
            popup.show(evt.getComponent(), evt.getX(), evt.getY());
//            System.out.println("Popup Rendered...");
        }

    }

    /**
     * @return the tableRow
     */
    public int getTableRow() {
        return tableRow;
    }

    /**
     * @param tableRow the tableRow to set
     */
    public void setTableRow(int tableRow) {
        this.tableRow = tableRow;
    }

    private Image getImageIcon(String image) {
        if (new File(image).exists()) {
            return new ImageIcon(image).getImage();
        } else {
            JOptionPane.showMessageDialog(null, "Image icon not found !", "No Icon", JOptionPane.WARNING_MESSAGE);
            return null;
        }
    }

    public void doSearchPwd(String text) {
        ArrayList pwdlist = null;
        if (!isShowPassword()) {
            pwdlist = Resource.getInstance().getSql().searchPasswords(text);
        } else {
            pwdlist = Resource.getInstance().getSql().searchPasswordsWPass(text);
        }
        int numrows = model.getRowCount();
        for (int i = numrows - 1; i >= 0; i--) {
            model.removeRow(i);
        }
        String[] row = new String[4];
        for (int i = 0; i < pwdlist.size(); i++) {
            pass = (Password) pwdlist.get(i);
            if (pass != null) {
                row[0] = pass.getUname();
                if (!isShowPassword()) {
                    row[1] = pass.getRplace();
                } else {
                    row[1] = pass.getUpass();
                    row[2] = pass.getRplace();
                }
                model.addRow(row);
            }
        }
        repaint();
    }

    private void doTermAcct() {
        System.out.println("Conn path: " + Resource.getInstance().getSql().getConnPath());
        H2JDBCParser parser = new H2JDBCParser(Resource.getInstance().getSql().getConnPath());
        System.out.println("Db Name: " + parser.getDbName());
        System.out.println("Name: " + parser.getName());
        System.out.println("Base Dir doTermAcct(): " + parser.getBaseDir());
        if (!Resource.getInstance().getSql().terminateAcct()) {
            File file = new File(parser.getBaseDir() + parser.getDbName() + ".h2.db");
            File folder = file.getParentFile();
            if (file.exists()) {
                file.delete();
                folder.delete();
                if (!file.exists()) {
                    moveBkAway();
                    JOptionPane.showMessageDialog(null, "Account have been terminated.\nSystem will exit now !", "Account Terminated", JOptionPane.INFORMATION_MESSAGE);
                    quitApp();
                } else {
                    JOptionPane.showMessageDialog(this, "There is an error terminating your account!", "Account Failed to Terminate", JOptionPane.ERROR_MESSAGE);
                }
            }
        } else {
            File file = new File(parser.getBaseDir() + parser.getDbName());
            if (file.exists()) {
                //file.delete();
                System.out.println(file.getPath());
            }
            moveBkAway();
            JOptionPane.showMessageDialog(null, "Account have been terminated.\nSystem will exit now !", "Account Terminated", JOptionPane.INFORMATION_MESSAGE);
            quitApp();
        }
    }

    private void checkShowPass() {
        String showPass = Resource.getInstance().getSystem().getProperty("gui.showpwd");
        if (showPass.equalsIgnoreCase("true")) {
            this.setShowPassword(true);
        } else {
            this.setShowPassword(false);
        }
    }

    /**
     * @return the showPassword
     */
    public boolean isShowPassword() {
        return showPassword;
    }

    /**
     * @param showPassword the showPassword to set
     */
    public void setShowPassword(boolean showPassword) {
        this.showPassword = showPassword;
    }

    private String getTimestampe(String data) {
        try {
            br = new BufferedReader(new FileReader("backup/" + data));
            String tempStr = br.readLine();
            String[] tempArray = tempStr.split("--");
            tempStr = tempArray[1].trim().toString();
            return tempStr;
        } catch (IOException ex) {
            Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, null, ex);
            return null;
        }
    }

    private Date convertDate(String rawStr, Date datetime) {
        String[] rawArray = rawStr.split(" ");
//        int day = getDayInt(rawArray[0].trim().toString());
        int year = Integer.parseInt(rawArray[5].trim().toString());
        int mon = getMonInt(rawArray[1].trim().toString());
        int date = Integer.parseInt(rawArray[2].trim().toString());
        String[] timeArray = rawArray[3].trim().toString().split(":");
        int hour = Integer.parseInt(timeArray[0].trim().toString());
        int min = Integer.parseInt(timeArray[1].trim().toString());
        int sec = Integer.parseInt(timeArray[2].trim().toString());
        datetime = new Date(year, mon, date, hour, min, sec);
        return datetime;
    }

    private int getDayInt(String data) {
        if (data.equalsIgnoreCase("Sun")) {
            return 0;
        } else if (data.equalsIgnoreCase("Mon")) {
            return 1;
        } else if (data.equalsIgnoreCase("Tue")) {
            return 2;
        } else if (data.equalsIgnoreCase("Wed")) {
            return 3;
        } else if (data.equalsIgnoreCase("Thu")) {
            return 4;
        } else if (data.equalsIgnoreCase("Fri")) {
            return 5;
        } else if (data.equalsIgnoreCase("Sat")) {
            return 6;
        } else {
            return -1;
        }
    }

    private int getMonInt(String data) {
        if (data.equalsIgnoreCase("Jan")) {
            return 0;
        } else if (data.equalsIgnoreCase("Feb")) {
            return 1;
        } else if (data.equalsIgnoreCase("Mar")) {
            return 2;
        } else if (data.equalsIgnoreCase("Apr")) {
            return 3;
        } else if (data.equalsIgnoreCase("May")) {
            return 4;
        } else if (data.equalsIgnoreCase("Jun")) {
            return 5;
        } else if (data.equalsIgnoreCase("Jul")) {
            return 6;
        } else if (data.equalsIgnoreCase("Aug")) {
            return 7;
        } else if (data.equalsIgnoreCase("Sep")) {
            return 8;
        } else if (data.equalsIgnoreCase("Oct")) {
            return 9;
        } else if (data.equalsIgnoreCase("Nov")) {
            return 10;
        } else if (data.equalsIgnoreCase("Dec")) {
            return 11;
        } else {
            return -1;
        }
    }

    private boolean changePassword(String newpwd) {

        ArrayList datalist = null;
        String orgpwdarray[] = String.valueOf(Resource.getInstance().getPassword()).split(" ");
        String orgpwd = orgpwdarray[1].toString();
        //System.out.println("User org pass: " + String.valueOf(orgpwd + "--"));
        boolean continueChanging = true; // check if it's worth for the changing of password to continue
        boolean dbpwdChanged = false;
        boolean encpwdChanged = false;
        boolean bkpwdChanged = false;
        //1.  Change db password
        if (continueChanging) { // check if it's worth for the changing of password to continue
            if (!Resource.getInstance().getSql().changeDBPassword(newpwd)) { // if changing db pwd has problem(s)
                continueChanging = false; // stop changing
                return false; //get out
            } else {
                dbpwdChanged = true; // continue changing
                continueChanging = true; // continue changing
                //System.out.println("DB pwd changed !");
            }
        }
        //2.  Change enc password
        if (continueChanging) { // check if it's worth for the changing of password to continue
            try {
                H2JDBCParser parser = new H2JDBCParser(Resource.getInstance().getSystem().getProperty("db.connection")); // get JDBC Url
                String basedir = parser.getBaseDir(); // get base dir
                String dbname = parser.getDbName(); // get db name
                Resource.getInstance().getSql().disconnectDB(); // disconnect db before changing enc
                //System.out.println("Attempting to change file enc for basedir: "+basedir+", dbname: "+dbname+"...");
                org.h2.tools.ChangeFileEncryption.execute(basedir, dbname, "AES", orgpwd.toCharArray(), newpwd.toCharArray(), false); //change enc
                Resource.getInstance().setPassword(new String(newpwd + " " + newpwd).toCharArray()); // switch to new password
                Resource.getInstance().reconnectDB(); // reconnect db for use
                //System.out.println("Changed enc done...");
                encpwdChanged = true; // continue changing
                continueChanging = true; // continue changing
            } catch (SQLException ex) { //Change enc hits problem(s)
                Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, null, ex);
                //System.out.println("Attempting to revert to old password: "+orgpwd);
                Resource.getInstance().getSql().changeDBPassword(orgpwd);// revert database password
                Resource.getInstance().setPassword(orgpwd.toCharArray());
                continueChanging = false; // stop changing
                return false; // get out
            }
        }
        //3.  Change bk files password
        if (continueChanging) { // check if it's worth for the changing of password to continue
            // Loop through backup folder and change encryption for each backup file
            // if any file hits problem, stop and revert all file, revert db and enc-db changes
            int numerr = 0;
            String bkdir[] = new File(Resource.getInstance().getBk().getBkpath()).list();
            File tempfile = null;
            for (int i = 0; i < bkdir.length; i++) {
                //System.out.println("bkdir file: " + bkdir[i].toString());
                tempfile = new File(Resource.getInstance().getBk().getBkpath() + "/" + bkdir[i].toString());
                if (tempfile.exists()) {
                    datalist = getOldBackupFileContent(tempfile, orgpwd); //retrieve decrypted file content
                    if (!reEncryptBackup(tempfile, String.valueOf(Resource.getInstance().getPassword()), datalist)) {
                        numerr = numerr + 1;
                    }
                }
            }
            //System.out.println("Number of errors: " + numerr);
            if (numerr == 0) {
                bkpwdChanged = true;
            }
            if (numerr != 0) {// attempt to rescue all backup files, db and enc-db changes
                try {
                    // attempt to rescue all backup files, db and enc-db changes
                    for (int i = 0; i < bkdir.length; i++) {
                        //System.out.println("bkdir file: " + bkdir[i].toString());
                        tempfile = new File(Resource.getInstance().getBk().getBkpath() + "/" + bkdir[i].toString());
                        if (tempfile.exists()) {
                            datalist = getOldBackupFileContent(tempfile, String.valueOf(Resource.getInstance().getPassword())); //retrieve decrypted file content
                            reEncryptBackup(tempfile, orgpwd + " " + orgpwd, datalist);
                        }
                    }
                    Resource.getInstance().getSql().changeDBPassword(orgpwd); // revert database password
                    Resource.getInstance().setPassword(orgpwd.toCharArray());
                    H2JDBCParser parser = new H2JDBCParser(Resource.getInstance().getSystem().getProperty("db.connection")); // get JDBC Url
                    String basedir = parser.getBaseDir(); // get base dir
                    System.out.println("SHIT base dir: " + basedir);
                    String dbname = parser.getDbName(); // get db name
                    System.out.println("SHIT name: " + dbname);
                    Resource.getInstance().getSql().disconnectDB(); // disconnect db before changing enc
                    //System.out.println("Attempting to change file enc for basedir: "+basedir+", dbname: "+dbname+"...");
                    org.h2.tools.ChangeFileEncryption.execute(basedir, dbname, "AES", newpwd.toCharArray(), orgpwd.toCharArray(), false); //change enc
                    Resource.getInstance().setPassword(new String(orgpwd + " " + orgpwd).toCharArray()); // switch to new password
                    Resource.getInstance().reconnectDB(); // reconnect db for use
                    bkpwdChanged = false;
                } catch (SQLException ex) {
                    Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, null, ex);
                    return false; // get out
                }
            }

        }
        //Finally, check if all are changed.
        //System.out.println("dbpwdChanged: " + dbpwdChanged + ", encpwdChanged: " + encpwdChanged + ", bkpwdChanged: " + bkpwdChanged);
        if (dbpwdChanged == true && encpwdChanged == true && bkpwdChanged == true) {

            return true;

        } else {
            return false;
        }
    }

    public ArrayList getOldBackupFileContent(File file, String orgpwd) { // uses old password to get encrypted backup content
        ArrayList buff = null;
        StringBuffer decrypt = new StringBuffer();
        try {
            BufferedReader br = new BufferedReader(new FileReader(file));
            buff = new ArrayList();
            String str;
            buff.add(br.readLine());
            str = br.readLine(); //Reads in the delete all statement
            buff.add(str);
            String p = orgpwd + " " + orgpwd;
            //System.out.println("Going to decrypt with old pwd: "+p);
            byte[] passBytes = Resource.getInstance().getAescrypt().hashpwd(p);
            while ((str = br.readLine()) != null) {
                decrypt.append(str);
                //System.out.println("Read in: "+str);
            }
            br.close();
            buff.add(Resource.getInstance().getAescrypt().ByteToString(Resource.getInstance().getAescrypt().decryptFile(Resource.getInstance().getAescrypt().HexToByte(decrypt.toString()), passBytes)));
        } catch (IOException ex) {
            Logger.getLogger(Restore.class.getName()).log(Level.SEVERE, null, ex);
        }
        return buff;
    }

    public boolean reEncryptBackup(File file, String encpwd, ArrayList datalist) {
        try {
            //Encrypt data buffer and merging data to buff
            byte[] cipherBytes = null;
            byte[] passBytes = null;
            StringBuffer header = new StringBuffer();
            StringBuffer data = new StringBuffer();
            try {
                String p = encpwd;
                passBytes = Resource.getInstance().getAescrypt().hashpwd(p);
                //java.util.Date today = new java.util.Date(); //Getting current Data/Time
                //String currentDT = today.toString();
                //header.append("-- " + currentDT + "\n");
                //System.out.println("App: "+datalist.get(0).toString());
                header.append(datalist.get(0).toString());
                for (int i = 1; i < datalist.size(); i++) {
                    //System.out.println(datalist.get(i));
                    data.append(datalist.get(i).toString());
                }
                //System.out.println("---");
                cipherBytes = Resource.getInstance().getAescrypt().encryptFile(data.toString(), passBytes);
            } catch (NullPointerException ex) {
                Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, null, ex);
                return false;
            }
            //data.append(getRes().getAescrypt().ByteToHex(cipherBytes));
            //Writing to file
            Writer output = null;
            output = new BufferedWriter(new FileWriter(file));
            //Write header
            if (header.toString().contains("\nDELETE FROM PASSWORDSTORE;\n")) {
                output.write(header.toString() + "\n");
            } else {
                output.write(header.toString() + "\nDELETE FROM PASSWORDSTORE;\n");
            }
            //Write encrypted data
            output.write(Resource.getInstance().getAescrypt().ByteToHex(cipherBytes));
            output.close();
            return true;
        } catch (IOException ex) {
            Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, null, ex);
            return false;
        }
    }

    private void moveBkAway() {
        File temp = null;
        File bk = new File("backup");
        int opt = JOptionPane.showConfirmDialog(null, "Do you want to preserve your backup files ?", "Preserve Backup", JOptionPane.YES_NO_OPTION);
        if (opt == JOptionPane.YES_OPTION) {

            java.util.Date date = new java.util.Date();
            temp = new File("backup-" + date.toString() + ".old");
            temp.mkdir();
            bk.renameTo(temp);
            JOptionPane.showMessageDialog(null, "Your backup folder has been moved to: \n" + temp.getAbsolutePath(), "Preserve Backup", JOptionPane.INFORMATION_MESSAGE);
        } else {
            if (bk.exists()) {
                bk.delete();
                if (bk.exists()) {
                    JOptionPane.showMessageDialog(null, "There is a problem removing your backup folder.\nPlease manually delete your own backup folder at: \n" + temp.getAbsolutePath(), "Backup Delete Failure", JOptionPane.ERROR_MESSAGE);
                }
            } else {
                JOptionPane.showMessageDialog(null, "Your backup folder has been deleted.", "Backup Deleted", JOptionPane.INFORMATION_MESSAGE);
            }
        }
    }

    /**
     * @return the miniOnClose
     */
    public boolean isMiniOnClose() {
        return miniOnClose;
    }

    /**
     * @param miniOnClose the miniOnClose to set
     */
    public void setMiniOnClose(boolean miniOnClose) {
        this.miniOnClose = miniOnClose;
    }

    /**
     * @return the trayIcon
     */
    public TrayIcon getTrayIcon() {
        return trayIcon;
    }

    /**
     * @param trayIcon the trayIcon to set
     */
    public void setTrayIcon(TrayIcon trayIcon) {
        this.trayIcon = trayIcon;
    }

    private void updateSystemProperties() {
        system = Resource.getInstance().getSystem();
        system.setProperty("gui.showpwd", "" + viewTable.isSelected());
        system.setProperty("gui.lockWin", "" + enableLock.isSelected());

        int timeout = 3;
        try {
            timeout = Integer.parseInt(lockDownTF.getText());
            if (timeout <= 0) {
                timeout = 3;
            }
        } catch (NumberFormatException ex) {
        }

        system.setProperty("gui.lockMin", "" + timeout);
        system.setProperty("gui.minOnClose", "" + minWindow.isSelected());
        system.setProperty("gui.pref", "" + lafCB.getSelectedItem().toString().trim().toLowerCase());
        system.setProperty("gui.lockOnMin", "" + lockOnMinCB.isSelected());
        system.setProperty("sys.dbExport", "" + expFrmtCB.getSelectedItem().toString().trim().toLowerCase());
        Resource.getInstance().setSystem(system);
        Resource.getInstance().getSystemProperties();
        //System.out.println(Resource.getInstance().getSystem().getProperty("gui.showpwd"));//Diagnostics
        checkShowPass();
        //System.out.println("Show Pass: " + isShowPassword());//Diagnostics
        initTableModel();
        initTableData();
        initMainTabs();
        adjustSystem();
    }

    /**
     * Decrypt backup file. 
     * Checking if possibility of existence of destination file or source file must be done at the side that called this method.
     * @param targetfile
     * @param destination
     * @param mode
     * @param password
     * @return
     */
    private boolean doDecryptBackupFile(String targetfile, String destination, int mode, char[] password) {
        BufferedReader in = null;
        Writer out = null;
        File targetFile = null;
        File destFile = null;
        String str;
        byte[] passBytes = null;
        StringBuilder buff = new StringBuilder();
        try {
            targetFile = new File(targetfile);
            destFile = new File(destination);
            destFile.createNewFile();
            //System.out.println("Target file: " + targetFile.getName() + "\nDest file: " + destFile.getName());
            in = new BufferedReader(new FileReader(targetFile));
            out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(destFile), "UTF8"));
            if (mode == 0) {
                //Backup folder decryption - use current user's password
                passBytes = Resource.getInstance().getAescrypt().hashpwd(new String(Resource.getInstance().getPassword()));
            } else if (mode == 1) {
                //Specific file decyrption - use supplied password
                passBytes = Resource.getInstance().getAescrypt().hashpwd(new String(password) + " " + new String(password));
            } else {
                //bad mode !byte[] passBytes
            }
            //System.out.println("Mode set...done...");
            if (passBytes != null) {
                //System.out.println("Passbytes len: " + passBytes.length);
                while ((str = in.readLine()) != null) {
                    //System.out.println("Reading: " + str);
                    if (str.startsWith("--")) {
                        // Ignore
                    } else if (str.equals("DELETE FROM PASSWORDSTORE;")) {
                        out.write("DELETE FROM PASSWORDSTORE;\n");
                    } else {
                        buff.append(str);
                    }
                }
                str = Resource.getInstance().getAescrypt().ByteToString(Resource.getInstance().getAescrypt().decryptFile(Resource.getInstance().getAescrypt().HexToByte(buff.toString()), passBytes));
                //System.out.println("Raw: " + str);//Diagnostics
                //Check encryption if successful
                if ((str.startsWith("DELETE")) || (str.startsWith("INSERT"))) {//INSERT
                    //purify the characters.
                    //System.out.println("Bef: "+str);//Diagnostics
                    String[] stra = str.split(";");
                    buff = new StringBuilder();
                    for (int i = 0; i < stra.length; i++) {
                        if (i == (stra.length - 1)) {
                            //Do nothing as it may contain unneeded buffer characters.
                        } else {
                            buff.append(stra[i].toString() + ";\n");
                        }
                    }
                    str = buff.toString();
                    //System.out.println("Aft: " + str);//Diagnostics
                    out.write(str);
                    out.flush();
                    out.close();
                    in.close();
                    return true;
                } else {
                    out.flush();
                    out.close();
                    in.close();
                    if (destFile.exists()) {
                        destFile.delete();
                    }
                    return false;
                }
            }
            out.close();
            in.close();
        } catch (IOException ex) {
            Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, null, ex);
        }
        return false;
    }

    private boolean doDeleteBackup() {
        int selectedVal = bkFileTable.getSelectedRow();
        if (selectedVal != -1) {
            File file = new File(Resource.getInstance().getBk().getBkpath() + "/" + (String) bkFileTable.getValueAt(selectedVal, 0));
            int respond = JOptionPane.showConfirmDialog(null, "Do really you want to DELETE: " + file.getName() + " ?", "Delete Backup File", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
            if (respond == JOptionPane.YES_OPTION) {
                file.delete();
                if (file.exists()) {
                    JOptionPane.showMessageDialog(this, file.getName() + ", failed to be deleted.", "Delete Backup File FAILED", JOptionPane.ERROR_MESSAGE);
                } else {
                    this.initBkFileTable();
                    JOptionPane.showMessageDialog(this, file.getName() + ", has been deleted .", "Backup File Deleted", JOptionPane.INFORMATION_MESSAGE);
                }
            }
        }
        return false;
    }

    private void cleanTable(JTable table) {
        while (table.getModel().getRowCount() > 0) {
            table.remove(0);
        }
    }

    /**
     * Use for preventing cells on table to be edited directly
     */
    public class MyDefaultTableModel extends DefaultTableModel {

        public MyDefaultTableModel() {
            super();
        }

        @Override
        public boolean isCellEditable(int row, int col) {
            return false;
        }
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        popup = new javax.swing.JPopupMenu();
        viewPwdBtn = new javax.swing.JMenuItem();
        delPwdBtn = new javax.swing.JMenuItem();
        copyUsername = new javax.swing.JMenuItem();
        copyPassword = new javax.swing.JMenuItem();
        copyRQ = new javax.swing.JMenuItem();
        searchPane = new javax.swing.JPanel();
        searchLeftPane = new javax.swing.JPanel();
        searchLbl = new javax.swing.JLabel();
        searchTf = new javax.swing.JTextField();
        doSearchBtn = new javax.swing.JButton();
        searchRightPane = new javax.swing.JPanel();
        closeSearchBtn = new javax.swing.JButton();
        buttonGroup1 = new javax.swing.ButtonGroup();
        decryptBackupPane = new javax.swing.JPanel();
        decBkBtmPane = new javax.swing.JPanel();
        restoreRefreshBtn1 = new javax.swing.JButton();
        decryptBkBtn = new javax.swing.JButton();
        decBkContPane = new javax.swing.JPanel();
        jLabel11 = new javax.swing.JLabel();
        decBkContTable = new javax.swing.JPanel();
        jScrollPane4 = new javax.swing.JScrollPane();
        bkFileTable1 = new javax.swing.JTable();
        decryptOwnPane = new javax.swing.JPanel();
        decOwnBtmPane = new javax.swing.JPanel();
        clearDecOwnBtn = new javax.swing.JButton();
        decryptOwnBtn = new javax.swing.JButton();
        decOwnContPane = new javax.swing.JPanel();
        jLabel9 = new javax.swing.JLabel();
        decOwnFileTf = new javax.swing.JTextField();
        jButton4 = new javax.swing.JButton();
        jLabel10 = new javax.swing.JLabel();
        decOwnPwdTf = new javax.swing.JPasswordField();
        decOwnDelCB = new javax.swing.JCheckBox();
        jLabel15 = new javax.swing.JLabel();
        quitBtn = new javax.swing.JButton();
        mainTabPane = new javax.swing.JTabbedPane();
        passwordTab = new javax.swing.JPanel();
        contentPane = new javax.swing.JPanel();
        scroll = new javax.swing.JScrollPane();
        table = new javax.swing.JTable();
        toolbar = new javax.swing.JToolBar();
        refreshBtn = new javax.swing.JButton();
        newBtn = new javax.swing.JButton();
        searchBtn = new javax.swing.JButton();
        clearClipBtn = new javax.swing.JButton();
        lockWinBtn = new javax.swing.JButton();
        settingsTab = new javax.swing.JPanel();
        settingsTabPane = new javax.swing.JTabbedPane();
        generalTab = new javax.swing.JPanel();
        generalPane = new javax.swing.JPanel();
        viewTable = new javax.swing.JCheckBox();
        enableLock = new javax.swing.JCheckBox();
        lockDownTF = new javax.swing.JTextField();
        saveGenSetBtn = new javax.swing.JButton();
        jLabel7 = new javax.swing.JLabel();
        lafCB = new javax.swing.JComboBox();
        minWindow = new javax.swing.JCheckBox();
        jScrollPane6 = new javax.swing.JScrollPane();
        jTextArea2 = new javax.swing.JTextArea();
        lockOnMinCB = new javax.swing.JCheckBox();
        userAccountTab = new javax.swing.JPanel();
        chgPwdPane = new javax.swing.JPanel();
        chgPwdLbl = new javax.swing.JLabel();
        chgPwdTf = new javax.swing.JPasswordField();
        chgPwdBtn = new javax.swing.JButton();
        tmAcctPane = new javax.swing.JPanel();
        termAcctBtn = new javax.swing.JButton();
        aboutTab = new javax.swing.JPanel();
        jLabel16 = new javax.swing.JLabel();
        jLabel17 = new javax.swing.JLabel();
        jLabel18 = new javax.swing.JLabel();
        jLabel19 = new javax.swing.JLabel();
        jScrollPane5 = new javax.swing.JScrollPane();
        jTextArea1 = new javax.swing.JTextArea();
        jLabel20 = new javax.swing.JLabel();
        toolsTab = new javax.swing.JPanel();
        toolsTabPane = new javax.swing.JTabbedPane();
        backupTab = new javax.swing.JPanel();
        backupPane = new javax.swing.JPanel();
        bkBtn = new javax.swing.JButton();
        restorePane = new javax.swing.JPanel();
        restorePanel = new javax.swing.JPanel();
        bkPane = new javax.swing.JPanel();
        bkBottomPane = new javax.swing.JPanel();
        delBkBtn = new javax.swing.JButton();
        restoreRefreshBtn = new javax.swing.JButton();
        restoreSelectBtn = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        bkFileTable = new javax.swing.JTable();
        exportTab = new javax.swing.JPanel();
        exportPane = new javax.swing.JPanel();
        exportPanel = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        expFrmtCB = new javax.swing.JComboBox();
        jLabel2 = new javax.swing.JLabel();
        dbFilenameTF = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        dbExportFolderTF = new javax.swing.JTextField();
        jButton1 = new javax.swing.JButton();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jButton2 = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();
        importPanel = new javax.swing.JPanel();
        jLabel21 = new javax.swing.JLabel();
        dbFilenameTF1 = new javax.swing.JTextField();
        fileBtn = new javax.swing.JButton();
        importBtn = new javax.swing.JButton();
        clearImpBtn = new javax.swing.JButton();
        decryptTab = new javax.swing.JPanel();
        decryptPane = new javax.swing.JPanel();
        decUpperPane = new javax.swing.JPanel();
        backupRB = new javax.swing.JRadioButton();
        ownRB = new javax.swing.JRadioButton();
        decTargetFolderTf = new javax.swing.JTextField();
        jLabel14 = new javax.swing.JLabel();
        targetFolderBtn = new javax.swing.JButton();
        jLabel13 = new javax.swing.JLabel();
        decTargetFileTf = new javax.swing.JTextField();
        jLabel12 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        detailsPane = new javax.swing.JPanel();

        viewPwdBtn.setText("View");
        viewPwdBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                viewPwdBtnActionPerformed(evt);
            }
        });
        popup.add(viewPwdBtn);

        delPwdBtn.setText("Delete");
        delPwdBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                delPwdBtnActionPerformed(evt);
            }
        });
        popup.add(delPwdBtn);

        copyUsername.setText("copy Username");
        copyUsername.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                copyUsernameActionPerformed(evt);
            }
        });
        popup.add(copyUsername);

        copyPassword.setText("copy Password");
        copyPassword.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                copyPasswordActionPerformed(evt);
            }
        });
        popup.add(copyPassword);

        copyRQ.setText("copy Required Place");
        copyRQ.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                copyRQActionPerformed(evt);
            }
        });
        popup.add(copyRQ);

        searchPane.setLayout(new java.awt.BorderLayout());

        searchLeftPane.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.LEFT));

        searchLbl.setText("Search: ");
        searchLeftPane.add(searchLbl);

        searchTf.setColumns(20);
        searchTf.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                searchTfActionPerformed(evt);
            }
        });
        searchTf.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                searchTfKeyPressed(evt);
            }
        });
        searchLeftPane.add(searchTf);

        doSearchBtn.setText("Go");
        doSearchBtn.setToolTipText("Begin searching");
        doSearchBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                doSearchBtnActionPerformed(evt);
            }
        });
        searchLeftPane.add(doSearchBtn);

        searchPane.add(searchLeftPane, java.awt.BorderLayout.WEST);

        searchRightPane.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.RIGHT));

        closeSearchBtn.setText("Close");
        closeSearchBtn.setToolTipText("Close search panel");
        closeSearchBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                closeSearchBtnActionPerformed(evt);
            }
        });
        searchRightPane.add(closeSearchBtn);

        searchPane.add(searchRightPane, java.awt.BorderLayout.EAST);

        decryptBackupPane.setLayout(new java.awt.BorderLayout());

        decBkBtmPane.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.RIGHT));

        restoreRefreshBtn1.setText("Refresh");
        restoreRefreshBtn1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                restoreRefreshBtn1ActionPerformed(evt);
            }
        });
        decBkBtmPane.add(restoreRefreshBtn1);

        decryptBkBtn.setText("Decrypt");
        decryptBkBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                decryptBkBtnActionPerformed(evt);
            }
        });
        decBkBtmPane.add(decryptBkBtn);

        decryptBackupPane.add(decBkBtmPane, java.awt.BorderLayout.SOUTH);

        jLabel11.setText("Select Backup File to Decrypt: ");

        decBkContTable.setLayout(new java.awt.BorderLayout());

        jScrollPane4.setPreferredSize(new java.awt.Dimension(200, 402));

        bkFileTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {

            }
        ));
        jScrollPane4.setViewportView(bkFileTable1);

        decBkContTable.add(jScrollPane4, java.awt.BorderLayout.CENTER);

        javax.swing.GroupLayout decBkContPaneLayout = new javax.swing.GroupLayout(decBkContPane);
        decBkContPane.setLayout(decBkContPaneLayout);
        decBkContPaneLayout.setHorizontalGroup(
            decBkContPaneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(decBkContPaneLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(decBkContPaneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(decBkContTable, javax.swing.GroupLayout.DEFAULT_SIZE, 246, Short.MAX_VALUE)
                    .addComponent(jLabel11))
                .addContainerGap())
        );
        decBkContPaneLayout.setVerticalGroup(
            decBkContPaneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(decBkContPaneLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel11)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(decBkContTable, javax.swing.GroupLayout.DEFAULT_SIZE, 173, Short.MAX_VALUE)
                .addContainerGap())
        );

        decryptBackupPane.add(decBkContPane, java.awt.BorderLayout.CENTER);

        decryptOwnPane.setLayout(new java.awt.BorderLayout());

        decOwnBtmPane.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.RIGHT));

        clearDecOwnBtn.setText("Clear");
        clearDecOwnBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                clearDecOwnBtnActionPerformed(evt);
            }
        });
        decOwnBtmPane.add(clearDecOwnBtn);

        decryptOwnBtn.setText("Decrypt");
        decryptOwnBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                decryptOwnBtnActionPerformed(evt);
            }
        });
        decOwnBtmPane.add(decryptOwnBtn);

        decryptOwnPane.add(decOwnBtmPane, java.awt.BorderLayout.SOUTH);

        jLabel9.setText("Target File: ");

        jButton4.setText("...");
        jButton4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton4ActionPerformed(evt);
            }
        });

        jLabel10.setText("Password: ");

        decOwnDelCB.setText("Delete decrypted files: ");
        decOwnDelCB.setHorizontalTextPosition(javax.swing.SwingConstants.LEFT);

        jLabel15.setFont(new java.awt.Font("DejaVu Sans", 1, 13));
        jLabel15.setText("Target for decryption:");

        javax.swing.GroupLayout decOwnContPaneLayout = new javax.swing.GroupLayout(decOwnContPane);
        decOwnContPane.setLayout(decOwnContPaneLayout);
        decOwnContPaneLayout.setHorizontalGroup(
            decOwnContPaneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(decOwnContPaneLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(decOwnContPaneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel15)
                    .addGroup(decOwnContPaneLayout.createSequentialGroup()
                        .addGroup(decOwnContPaneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel9)
                            .addComponent(jLabel10))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(decOwnContPaneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(decOwnPwdTf, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 162, Short.MAX_VALUE)
                            .addComponent(decOwnFileTf, javax.swing.GroupLayout.Alignment.TRAILING))
                        .addGap(6, 6, 6)
                        .addComponent(jButton4))
                    .addComponent(decOwnDelCB))
                .addGap(30, 30, 30))
        );
        decOwnContPaneLayout.setVerticalGroup(
            decOwnContPaneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(decOwnContPaneLayout.createSequentialGroup()
                .addGap(12, 12, 12)
                .addComponent(jLabel15)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(decOwnContPaneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel9)
                    .addComponent(decOwnFileTf, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButton4))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(decOwnContPaneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel10)
                    .addComponent(decOwnPwdTf, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(decOwnDelCB)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        decryptOwnPane.add(decOwnContPane, java.awt.BorderLayout.CENTER);

        quitBtn.setText("Quit");
        quitBtn.setToolTipText("Shutdown PasswordStore");
        quitBtn.setFocusable(false);
        quitBtn.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        quitBtn.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        quitBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                quitBtnActionPerformed(evt);
            }
        });

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("PasswordStore");

        passwordTab.setLayout(new java.awt.BorderLayout());

        contentPane.setLayout(new java.awt.BorderLayout());

        table.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {},
                {},
                {},
                {}
            },
            new String [] {

            }
        ));
        table.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tableMouseClicked(evt);
            }
            public void mousePressed(java.awt.event.MouseEvent evt) {
                tableMousePressed(evt);
            }
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                tableMouseReleased(evt);
            }
        });
        scroll.setViewportView(table);

        contentPane.add(scroll, java.awt.BorderLayout.CENTER);

        toolbar.setRollover(true);

        refreshBtn.setText("Refresh");
        refreshBtn.setToolTipText("Refresh view");
        refreshBtn.setFocusable(false);
        refreshBtn.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        refreshBtn.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        refreshBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                refreshBtnActionPerformed(evt);
            }
        });
        toolbar.add(refreshBtn);

        newBtn.setText("New");
        newBtn.setToolTipText("New password profile");
        newBtn.setFocusable(false);
        newBtn.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        newBtn.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        newBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                newBtnActionPerformed(evt);
            }
        });
        toolbar.add(newBtn);

        searchBtn.setText("Search");
        searchBtn.setToolTipText("Search password profiles");
        searchBtn.setFocusable(false);
        searchBtn.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        searchBtn.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        searchBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                searchBtnActionPerformed(evt);
            }
        });
        toolbar.add(searchBtn);

        clearClipBtn.setText("Clear Clipboard");
        clearClipBtn.setToolTipText("Clear entire clipboard");
        clearClipBtn.setFocusable(false);
        clearClipBtn.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        clearClipBtn.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        clearClipBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                clearClipBtnActionPerformed(evt);
            }
        });
        toolbar.add(clearClipBtn);

        lockWinBtn.setText("Lock Window");
        lockWinBtn.setToolTipText("Lock PasswordStore Window");
        lockWinBtn.setFocusable(false);
        lockWinBtn.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        lockWinBtn.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        lockWinBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                lockWinBtnActionPerformed(evt);
            }
        });
        toolbar.add(lockWinBtn);

        contentPane.add(toolbar, java.awt.BorderLayout.PAGE_START);

        passwordTab.add(contentPane, java.awt.BorderLayout.CENTER);

        mainTabPane.addTab("Password", passwordTab);

        settingsTab.setLayout(new java.awt.BorderLayout());

        settingsTabPane.setPreferredSize(new java.awt.Dimension(365, 245));

        generalTab.setLayout(new java.awt.BorderLayout());

        viewTable.setText("Enable viewing of passwords in table.");

        enableLock.setText("Enable locking of PasswordStore after mins: ");
        enableLock.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                enableLockItemStateChanged(evt);
            }
        });

        lockDownTF.setColumns(2);
        lockDownTF.setEnabled(false);

        saveGenSetBtn.setText("Save General Settings");
        saveGenSetBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                saveGenSetBtnActionPerformed(evt);
            }
        });

        jLabel7.setText("Look and Feel: ");

        lafCB.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "A03", "Swing" }));
        lafCB.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                lafCBActionPerformed(evt);
            }
        });

        minWindow.setText("Iconify Window when closed.");

        jScrollPane6.setBorder(javax.swing.BorderFactory.createTitledBorder("Note: "));

        jTextArea2.setColumns(20);
        jTextArea2.setEditable(false);
        jTextArea2.setLineWrap(true);
        jTextArea2.setRows(5);
        jTextArea2.setText(" - Please restart PasswordStore after changing settings !\n - Minutes for lock window timeout cannot be 0 or less.");
        jTextArea2.setWrapStyleWord(true);
        jTextArea2.setDisabledTextColor(new java.awt.Color(5, 3, 1));
        jTextArea2.setEnabled(false);
        jScrollPane6.setViewportView(jTextArea2);

        lockOnMinCB.setText("Enable locking of PasswordStore upon minimise.");

        javax.swing.GroupLayout generalPaneLayout = new javax.swing.GroupLayout(generalPane);
        generalPane.setLayout(generalPaneLayout);
        generalPaneLayout.setHorizontalGroup(
            generalPaneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(generalPaneLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(generalPaneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane6, javax.swing.GroupLayout.DEFAULT_SIZE, 517, Short.MAX_VALUE)
                    .addComponent(viewTable)
                    .addGroup(generalPaneLayout.createSequentialGroup()
                        .addComponent(enableLock)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(lockDownTF, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(minWindow)
                    .addComponent(saveGenSetBtn, javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(lockOnMinCB)
                    .addGroup(generalPaneLayout.createSequentialGroup()
                        .addComponent(jLabel7)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(lafCB, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        generalPaneLayout.setVerticalGroup(
            generalPaneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(generalPaneLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(viewTable)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(generalPaneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(enableLock)
                    .addComponent(lockDownTF, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(minWindow)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(lockOnMinCB)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(generalPaneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel7)
                    .addComponent(lafCB, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 112, Short.MAX_VALUE)
                .addComponent(jScrollPane6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(saveGenSetBtn)
                .addContainerGap())
        );

        generalTab.add(generalPane, java.awt.BorderLayout.CENTER);

        settingsTabPane.addTab("General", generalTab);

        chgPwdPane.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Change User Account Password", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("DejaVu Sans", 1, 13))); // NOI18N

        chgPwdLbl.setText("Change Password: ");

        chgPwdTf.setColumns(20);
        chgPwdTf.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                chgPwdTfKeyPressed(evt);
            }
        });

        chgPwdBtn.setText("Change Password");
        chgPwdBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                chgPwdBtnActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout chgPwdPaneLayout = new javax.swing.GroupLayout(chgPwdPane);
        chgPwdPane.setLayout(chgPwdPaneLayout);
        chgPwdPaneLayout.setHorizontalGroup(
            chgPwdPaneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(chgPwdPaneLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(chgPwdPaneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(chgPwdPaneLayout.createSequentialGroup()
                        .addComponent(chgPwdLbl)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(chgPwdTf, javax.swing.GroupLayout.DEFAULT_SIZE, 408, Short.MAX_VALUE))
                    .addComponent(chgPwdBtn, javax.swing.GroupLayout.Alignment.TRAILING))
                .addContainerGap())
        );
        chgPwdPaneLayout.setVerticalGroup(
            chgPwdPaneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(chgPwdPaneLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(chgPwdPaneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(chgPwdLbl)
                    .addComponent(chgPwdTf, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(chgPwdBtn)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        tmAcctPane.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Terminate Account", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("DejaVu Sans", 1, 13))); // NOI18N

        termAcctBtn.setForeground(new java.awt.Color(255, 0, 0));
        termAcctBtn.setText("Terminate Account");
        termAcctBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                termAcctBtnActionPerformed(evt);
            }
        });
        tmAcctPane.add(termAcctBtn);

        javax.swing.GroupLayout userAccountTabLayout = new javax.swing.GroupLayout(userAccountTab);
        userAccountTab.setLayout(userAccountTabLayout);
        userAccountTabLayout.setHorizontalGroup(
            userAccountTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(chgPwdPane, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(tmAcctPane, javax.swing.GroupLayout.DEFAULT_SIZE, 537, Short.MAX_VALUE)
        );
        userAccountTabLayout.setVerticalGroup(
            userAccountTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(userAccountTabLayout.createSequentialGroup()
                .addComponent(chgPwdPane, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(tmAcctPane, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(229, Short.MAX_VALUE))
        );

        settingsTabPane.addTab("User", userAccountTab);

        jLabel16.setFont(new java.awt.Font("DejaVu Sans", 3, 14));
        jLabel16.setText("PasswordStore");

        jLabel17.setText("v 0.3 (Alpha)");

        jLabel18.setText("License: ");

        jLabel19.setText("GNU LGPL v3 <www.gnu.org/licenses/lgpl.html>");

        jScrollPane5.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        jTextArea1.setColumns(20);
        jTextArea1.setEditable(false);
        jTextArea1.setLineWrap(true);
        jTextArea1.setRows(5);
        jTextArea1.setText("For License: Refer to the above website or read the 'LICENSE-LGPL.html' file. (All H2 database codes still retain their H2 license)\n\nPlease read the 'PasswordStore' file (rename it with a '.txt' extension for Windows OS) for information on PasswordStore.\n\nPasswordStore Websites and Source Code Hostings:\nhttps://sites.google.com/site/thothtech/product-release/passwordstore\nhttp://freshmeat.net/projects/passwordstore\nhttps://launchpad.net/passwordstore\n\nCredits:\n - PasswordStore icon: Jeremiah\n - H2 database: H2 devs & Thomas Mueller (H2 Lead)\n - A03 LAF: Davide Raccagni ");
        jTextArea1.setWrapStyleWord(true);
        jScrollPane5.setViewportView(jTextArea1);

        jLabel20.setFont(new java.awt.Font("DejaVu Sans", 1, 13));
        jLabel20.setText("Release: -");

        javax.swing.GroupLayout aboutTabLayout = new javax.swing.GroupLayout(aboutTab);
        aboutTab.setLayout(aboutTabLayout);
        aboutTabLayout.setHorizontalGroup(
            aboutTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(aboutTabLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(aboutTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(aboutTabLayout.createSequentialGroup()
                        .addComponent(jLabel16)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel17)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 256, Short.MAX_VALUE)
                        .addComponent(jLabel20))
                    .addGroup(aboutTabLayout.createSequentialGroup()
                        .addComponent(jLabel18)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel19)))
                .addContainerGap())
            .addComponent(jScrollPane5, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 537, Short.MAX_VALUE)
        );
        aboutTabLayout.setVerticalGroup(
            aboutTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(aboutTabLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(aboutTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel16)
                    .addComponent(jLabel17)
                    .addComponent(jLabel20))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(aboutTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel18)
                    .addComponent(jLabel19))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane5, javax.swing.GroupLayout.DEFAULT_SIZE, 337, Short.MAX_VALUE))
        );

        settingsTabPane.addTab("About", aboutTab);

        settingsTab.add(settingsTabPane, java.awt.BorderLayout.CENTER);

        mainTabPane.addTab("Settings", settingsTab);

        toolsTab.setLayout(new java.awt.BorderLayout());

        backupTab.setLayout(new java.awt.BorderLayout());

        backupPane.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Backup", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Dialog", 1, 12))); // NOI18N
        backupPane.setLayout(new java.awt.BorderLayout());

        bkBtn.setText("Backup");
        bkBtn.setToolTipText("Backup passwords");
        bkBtn.setFocusable(false);
        bkBtn.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        bkBtn.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        bkBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bkBtnActionPerformed(evt);
            }
        });
        backupPane.add(bkBtn, java.awt.BorderLayout.CENTER);

        backupTab.add(backupPane, java.awt.BorderLayout.NORTH);

        restorePane.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Restore", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Dialog", 1, 12))); // NOI18N
        restorePane.setPreferredSize(new java.awt.Dimension(200, 218));
        restorePane.setLayout(new java.awt.BorderLayout());

        restorePanel.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1));
        restorePanel.setLayout(new java.awt.BorderLayout());

        bkPane.setLayout(new java.awt.BorderLayout());
        restorePanel.add(bkPane, java.awt.BorderLayout.CENTER);

        bkBottomPane.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.RIGHT));

        delBkBtn.setText("Delete");
        delBkBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                delBkBtnActionPerformed(evt);
            }
        });
        bkBottomPane.add(delBkBtn);

        restoreRefreshBtn.setText("Refresh");
        restoreRefreshBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                restoreRefreshBtnActionPerformed(evt);
            }
        });
        bkBottomPane.add(restoreRefreshBtn);

        restoreSelectBtn.setText("Restore");
        restoreSelectBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                restoreSelectBtnActionPerformed(evt);
            }
        });
        bkBottomPane.add(restoreSelectBtn);

        restorePanel.add(bkBottomPane, java.awt.BorderLayout.SOUTH);

        restorePane.add(restorePanel, java.awt.BorderLayout.SOUTH);

        jScrollPane1.setPreferredSize(new java.awt.Dimension(200, 402));

        bkFileTable.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {

            }
        ));
        jScrollPane1.setViewportView(bkFileTable);

        restorePane.add(jScrollPane1, java.awt.BorderLayout.CENTER);

        backupTab.add(restorePane, java.awt.BorderLayout.CENTER);

        toolsTabPane.addTab("Backup", backupTab);

        exportTab.setName(""); // NOI18N
        exportTab.setLayout(new java.awt.BorderLayout());

        exportPanel.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Export Database", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.TOP, new java.awt.Font("Dialog", 1, 12))); // NOI18N
        exportPanel.setPreferredSize(new java.awt.Dimension(399, 218));

        jLabel1.setText("Export Format: ");

        expFrmtCB.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "SQL", "CSV" }));

        jLabel2.setText("Filename: ");

        dbFilenameTF.setColumns(15);

        jLabel3.setText("Folder: ");

        dbExportFolderTF.setColumns(15);
        dbExportFolderTF.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                dbExportFolderTFActionPerformed(evt);
            }
        });

        jButton1.setText("...");
        jButton1.setToolTipText("Use a File Chooser");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jLabel4.setText("Note: Do not include a file format in the 'Filename'.");

        jLabel5.setFont(new java.awt.Font("DejaVu Sans", 1, 13));
        jLabel5.setForeground(new java.awt.Color(255, 0, 0));
        jLabel5.setText("Warning: Exported formats are NOT ENCRYPTED.");

        jButton2.setText("Export");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        jButton3.setText("Clear");
        jButton3.setToolTipText("Clear Fields");
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout exportPanelLayout = new javax.swing.GroupLayout(exportPanel);
        exportPanel.setLayout(exportPanelLayout);
        exportPanelLayout.setHorizontalGroup(
            exportPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(exportPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(exportPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel5, javax.swing.GroupLayout.DEFAULT_SIZE, 505, Short.MAX_VALUE)
                    .addGroup(exportPanelLayout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(expFrmtCB, javax.swing.GroupLayout.PREFERRED_SIZE, 118, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(exportPanelLayout.createSequentialGroup()
                        .addComponent(jLabel2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(dbFilenameTF, javax.swing.GroupLayout.DEFAULT_SIZE, 452, Short.MAX_VALUE))
                    .addGroup(exportPanelLayout.createSequentialGroup()
                        .addComponent(jLabel3)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(dbExportFolderTF, javax.swing.GroupLayout.DEFAULT_SIZE, 413, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton1))
                    .addComponent(jLabel4)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, exportPanelLayout.createSequentialGroup()
                        .addComponent(jButton3)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton2)))
                .addContainerGap())
        );
        exportPanelLayout.setVerticalGroup(
            exportPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(exportPanelLayout.createSequentialGroup()
                .addComponent(jLabel5)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(exportPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(expFrmtCB, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(exportPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(dbFilenameTF, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(exportPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(dbExportFolderTF, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButton1))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel4)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 105, Short.MAX_VALUE)
                .addGroup(exportPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton2)
                    .addComponent(jButton3))
                .addContainerGap())
        );

        importPanel.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Import Database", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.TOP, new java.awt.Font("Dialog", 1, 12))); // NOI18N
        importPanel.setPreferredSize(new java.awt.Dimension(399, 218));

        jLabel21.setText("Filename: ");

        dbFilenameTF1.setColumns(15);

        fileBtn.setText("...");
        fileBtn.setToolTipText("Use a File Chooser");
        fileBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                fileBtnActionPerformed(evt);
            }
        });

        importBtn.setText("Import");
        importBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                importBtnActionPerformed(evt);
            }
        });

        clearImpBtn.setText("Clear");
        clearImpBtn.setToolTipText("Clear Fields");
        clearImpBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                clearImpBtnActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout importPanelLayout = new javax.swing.GroupLayout(importPanel);
        importPanel.setLayout(importPanelLayout);
        importPanelLayout.setHorizontalGroup(
            importPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(importPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(importPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, importPanelLayout.createSequentialGroup()
                        .addComponent(clearImpBtn)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(importBtn))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, importPanelLayout.createSequentialGroup()
                        .addComponent(jLabel21)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(dbFilenameTF1, javax.swing.GroupLayout.DEFAULT_SIZE, 401, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(fileBtn)))
                .addContainerGap())
        );
        importPanelLayout.setVerticalGroup(
            importPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, importPanelLayout.createSequentialGroup()
                .addGroup(importPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel21)
                    .addComponent(dbFilenameTF1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(fileBtn))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(importPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(clearImpBtn)
                    .addComponent(importBtn))
                .addContainerGap())
        );

        javax.swing.GroupLayout exportPaneLayout = new javax.swing.GroupLayout(exportPane);
        exportPane.setLayout(exportPaneLayout);
        exportPaneLayout.setHorizontalGroup(
            exportPaneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(importPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 537, Short.MAX_VALUE)
            .addComponent(exportPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 537, Short.MAX_VALUE)
        );
        exportPaneLayout.setVerticalGroup(
            exportPaneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(exportPaneLayout.createSequentialGroup()
                .addComponent(importPanel, javax.swing.GroupLayout.PREFERRED_SIZE, 103, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(exportPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 282, Short.MAX_VALUE))
        );

        exportTab.add(exportPane, java.awt.BorderLayout.CENTER);

        toolsTabPane.addTab("Import / Export", exportTab);

        decryptTab.setLayout(new java.awt.BorderLayout());

        decryptPane.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Decrypt File", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Dialog", 1, 12))); // NOI18N
        decryptPane.setLayout(new java.awt.BorderLayout());

        buttonGroup1.add(backupRB);
        backupRB.setText("'Backup' Folder");
        backupRB.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                backupRBItemStateChanged(evt);
            }
        });

        buttonGroup1.add(ownRB);
        ownRB.setText("Select your own");
        ownRB.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                ownRBItemStateChanged(evt);
            }
        });

        decTargetFolderTf.setColumns(10);

        jLabel14.setText("Folder: ");

        targetFolderBtn.setText("...");
        targetFolderBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                targetFolderBtnActionPerformed(evt);
            }
        });

        jLabel13.setText(".sql");

        decTargetFileTf.setColumns(10);
        decTargetFileTf.setText("decrypt");

        jLabel12.setText("Filename: ");

        jLabel6.setText("Decrypt PasswordStore backup files to:");

        javax.swing.GroupLayout decUpperPaneLayout = new javax.swing.GroupLayout(decUpperPane);
        decUpperPane.setLayout(decUpperPaneLayout);
        decUpperPaneLayout.setHorizontalGroup(
            decUpperPaneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(decUpperPaneLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(decUpperPaneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(decUpperPaneLayout.createSequentialGroup()
                        .addGroup(decUpperPaneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(decUpperPaneLayout.createSequentialGroup()
                                .addGroup(decUpperPaneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel12)
                                    .addComponent(jLabel14))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(decUpperPaneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(decTargetFileTf)
                                    .addComponent(decTargetFolderTf, javax.swing.GroupLayout.DEFAULT_SIZE, 187, Short.MAX_VALUE)))
                            .addComponent(jLabel6))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(decUpperPaneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel13)
                            .addComponent(targetFolderBtn, javax.swing.GroupLayout.PREFERRED_SIZE, 24, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(decUpperPaneLayout.createSequentialGroup()
                        .addComponent(ownRB)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(backupRB)))
                .addContainerGap(245, Short.MAX_VALUE))
        );
        decUpperPaneLayout.setVerticalGroup(
            decUpperPaneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(decUpperPaneLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel6)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(decUpperPaneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel12)
                    .addComponent(decTargetFileTf, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel13, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(decUpperPaneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel14)
                    .addGroup(decUpperPaneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(decTargetFolderTf, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(targetFolderBtn)))
                .addGap(9, 9, 9)
                .addGroup(decUpperPaneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(backupRB)
                    .addComponent(ownRB))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        decryptPane.add(decUpperPane, java.awt.BorderLayout.NORTH);

        detailsPane.setBorder(javax.swing.BorderFactory.createTitledBorder("Details"));
        detailsPane.setLayout(new java.awt.BorderLayout());
        decryptPane.add(detailsPane, java.awt.BorderLayout.CENTER);

        decryptTab.add(decryptPane, java.awt.BorderLayout.CENTER);

        toolsTabPane.addTab("Decrypt", decryptTab);

        toolsTab.add(toolsTabPane, java.awt.BorderLayout.CENTER);

        mainTabPane.addTab("Tools", toolsTab);

        getContentPane().add(mainTabPane, java.awt.BorderLayout.CENTER);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void refreshBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_refreshBtnActionPerformed
        // TODO add your handling code here:
        initTableData();
    }//GEN-LAST:event_refreshBtnActionPerformed

    private void newBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_newBtnActionPerformed
        // TODO add your handling code here:
        NewPasswordDialog dialog = new NewPasswordDialog();
        dialog.setVisible(true);
        dialog.setTitle("New Password");
        dialog.setIconImage(iconImg);
}//GEN-LAST:event_newBtnActionPerformed

    private void tableMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tableMousePressed
        // TODO add your handling code here:
        showPopup(evt);
    }//GEN-LAST:event_tableMousePressed

    private void viewPwdBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_viewPwdBtnActionPerformed
        // TODO add your handling code here:
        int selectedRow = this.getTableRow();
        if (selectedRow != -1) {
            String username = (String) table.getValueAt(selectedRow, 0);
            int rqplaceNum = 1;
            if (this.isShowPassword()) {
                rqplaceNum = 2;
            }
            String rqplace = (String) table.getValueAt(selectedRow, rqplaceNum);
            pass = new Password();
            pass.setUname(username);
            pass.setRplace(rqplace);
            String tempPass = Resource.getInstance().getSql().viewPassword(pass);
            pass.setUpass(tempPass);
            ViewPasswordDialog dialog = new ViewPasswordDialog(pass);
            dialog.setVisible(true);
            dialog.setLocationRelativeTo(this);
            dialog.setTitle("View Password");
            dialog.setIconImage(iconImg);
        }
    }//GEN-LAST:event_viewPwdBtnActionPerformed

    private void delPwdBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_delPwdBtnActionPerformed
        // TODO add your handling code here:
        String username = (String) table.getValueAt(this.getTableRow(), 0);
        int rqplaceNum = 1;
        if (this.isShowPassword()) {
            rqplaceNum = 2;
        }
        String rqplace = (String) table.getValueAt(this.getTableRow(), rqplaceNum);
        deletePassword(username, rqplace);
    }//GEN-LAST:event_delPwdBtnActionPerformed

    private void bkBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bkBtnActionPerformed
        // TODO add your handling code here:
        String bkpath = Resource.getInstance().getBk().doBackup();
        if (bkpath != null) {
            if (!bkpath.equals("empty")) {
                this.initBkFileTable();
                JOptionPane.showMessageDialog(this, "Backup to: " + bkpath + "\n Done !", "Backup Completed", JOptionPane.INFORMATION_MESSAGE);
            } else {
                JOptionPane.showMessageDialog(this, "There's no data to be backup.\n Done !", "Backup Completed", JOptionPane.INFORMATION_MESSAGE);
            }
        }
}//GEN-LAST:event_bkBtnActionPerformed

    private void restoreRefreshBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_restoreRefreshBtnActionPerformed
        // TODO add your handling code here:
        this.initBkFileTable();
    }//GEN-LAST:event_restoreRefreshBtnActionPerformed

    private void restoreSelectBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_restoreSelectBtnActionPerformed
        // TODO add your handling code here:
        int selectedVal = bkFileTable.getSelectedRow();
        if (selectedVal != -1) {
            //System.out.println("selected: " + (String) bkFileTable.getValueAt(selectedVal, 0));//Diagnostic
            this.doRestore((String) bkFileTable.getValueAt(selectedVal, 0));
        }
    }//GEN-LAST:event_restoreSelectBtnActionPerformed

    private void copyUsernameActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_copyUsernameActionPerformed
        // TODO add your handling code here:
        String username = (String) table.getValueAt(this.getTableRow(), 0);
        Resource.getInstance().getClip().copy(username);
    }//GEN-LAST:event_copyUsernameActionPerformed

    private void copyRQActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_copyRQActionPerformed
        // TODO add your handling code here:
        int rqplaceNum = 1;
        if (this.isShowPassword()) {
            rqplaceNum = 2;
        }
        String rqplace = (String) table.getValueAt(this.getTableRow(), rqplaceNum);
        Resource.getInstance().getClip().copy(rqplace);
    }//GEN-LAST:event_copyRQActionPerformed

    private void copyPasswordActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_copyPasswordActionPerformed
        // TODO add your handling code here:
        int rqplaceNum = 1;
        if (this.isShowPassword()) {
            rqplaceNum = 2;
        }
        String username = (String) table.getValueAt(this.getTableRow(), 0);
        String rqplace = (String) table.getValueAt(this.getTableRow(), rqplaceNum);
        pass = new Password();
        pass.setUname(username);
        pass.setRplace(rqplace);
        String tempPass = Resource.getInstance().getSql().viewPassword(pass);
        Resource.getInstance().getClip().copy(tempPass);
    }//GEN-LAST:event_copyPasswordActionPerformed

    private void clearClipBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_clearClipBtnActionPerformed
        // TODO add your handling code here:
        Resource.getInstance().getClip().clear();
    }//GEN-LAST:event_clearClipBtnActionPerformed

    private void searchTfActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_searchTfActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_searchTfActionPerformed

    private void searchBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_searchBtnActionPerformed
        // TODO add your handling code here:
        if (!isSearchShown) {
            contentLayout = (BorderLayout) contentPane.getLayout();
            Component comp = contentLayout.getLayoutComponent(BorderLayout.SOUTH);

            if (comp != null) {
                //System.out.println("Component found ! " + comp.getClass().getName());//Diagnostic
                contentPane.add(searchPane, BorderLayout.NORTH);
            } else {
                //System.out.println("Nothing found.");//Diagnostic
                contentPane.add(searchPane, BorderLayout.SOUTH);
            }
            searchTf.grabFocus();
            validate();
            isSearchShown = true;
        }
    }//GEN-LAST:event_searchBtnActionPerformed

    private void closeSearchBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_closeSearchBtnActionPerformed
        // TODO add your handling code here:
        contentPane.remove(searchPane);
        validate();
        this.initTableData();
        isSearchShown = false;
    }//GEN-LAST:event_closeSearchBtnActionPerformed

    private void doSearchBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_doSearchBtnActionPerformed
        // TODO add your handling code here:
        doSearchPwd(searchTf.getText());
    }//GEN-LAST:event_doSearchBtnActionPerformed

    private void searchTfKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_searchTfKeyPressed
        // TODO add your handling code here:
        if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
            doSearchPwd(searchTf.getText());
        }
    }//GEN-LAST:event_searchTfKeyPressed

    private void tableMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tableMouseReleased
        // TODO add your handling code here:
        showPopup(evt);
    }//GEN-LAST:event_tableMouseReleased

    private void termAcctBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_termAcctBtnActionPerformed
        // TODO add your handling code here:
        int respond = JOptionPane.showConfirmDialog(null, "Do you want to TERMINATE ACCOUNT ?", "Terminate Account", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
        if (respond == JOptionPane.YES_OPTION) {
            doTermAcct();
        }
    }//GEN-LAST:event_termAcctBtnActionPerformed

    private void chgPwdBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_chgPwdBtnActionPerformed
        // TODO add your handling code here:
        char[] textpasswd = chgPwdTf.getPassword();
        if (textpasswd.length < 8) {
            JOptionPane.showMessageDialog(null, "Password length needs to be 8 characters or more !", "Wrong Password Length", JOptionPane.WARNING_MESSAGE);
            chgPwdTf.setText("");
            chgPwdTf.grabFocus();
        } else {
            int respond = JOptionPane.showConfirmDialog(null, "Are you sure you want change password ?", "Change password ?", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
            if (respond == JOptionPane.YES_OPTION) {
                if (changePassword(String.valueOf(textpasswd))) {
                    JOptionPane.showMessageDialog(null, "Password have been successfully changed !", "Password Changed", JOptionPane.INFORMATION_MESSAGE);
                } else {
                    JOptionPane.showMessageDialog(null, "Password have FAILED to be changed !\nAttempted to REVERT to OLD PASSWORD done.", "Password Change FAILED", JOptionPane.ERROR_MESSAGE);
                }
                chgPwdTf.setText("");
                chgPwdTf.grabFocus();
            }
        }
    }//GEN-LAST:event_chgPwdBtnActionPerformed

    private void chgPwdTfKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_chgPwdTfKeyPressed
        // TODO add your handling code here:
        if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
            chgPwdBtnActionPerformed(null);
        }
    }//GEN-LAST:event_chgPwdTfKeyPressed

    private void lafCBActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_lafCBActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_lafCBActionPerformed

    private void saveGenSetBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saveGenSetBtnActionPerformed
        // TODO add your handling code here:
        updateSystemProperties();
    }//GEN-LAST:event_saveGenSetBtnActionPerformed

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
        // TODO add your handling code here:
        system = Resource.getInstance().getSystem();
        if (system.getProperty("sys.dbExport").equalsIgnoreCase("CSV")) {
            expFrmtCB.setSelectedItem("CSV");
        } else if (system.getProperty("sys.dbExport").equalsIgnoreCase("SQL")) {
            expFrmtCB.setSelectedItem("SQL");
        } else {
            expFrmtCB.setSelectedItem("SQLs");
        }
        dbFilenameTF.setText("");
        dbExportFolderTF.setText("");
    }//GEN-LAST:event_jButton3ActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        // TODO add your handling code here:
        JFileChooser chooser = new JFileChooser();
        chooser.setDialogTitle("Select export folder");
        chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
        if (chooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
            dbExportFolderTF.setText(chooser.getSelectedFile().toString());
        }
    }//GEN-LAST:event_jButton1ActionPerformed

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        // TODO add your handling code here:
        // Get values and check for empty fields before accepting. Centralize DbDump as a Resource obj and use from there.
        String exportFolder = dbExportFolderTF.getText();
        String exportFile = dbFilenameTF.getText();
        String dump = "";
        if (exportFile.isEmpty() || exportFolder.isEmpty()) {
            JOptionPane.showMessageDialog(null, "Please enter a filename and select an export folder for export !", "Empty Fields", JOptionPane.WARNING_MESSAGE);
        } else {
            if (new File(exportFolder).exists()) {
                if (expFrmtCB.getSelectedItem().equals("CSV")) {
                    dump = exportFolder + "/" + exportFile + ".csv";
                    //System.out.println("Dump file: " + dump);
                    if (new File(dump).exists()) {
                        //Wants to overwrite file... continue, else revert.
                        int num = JOptionPane.showConfirmDialog(null, "File: '" + dump + "' is currently available.\nDo you want to OVERWRITE it ?", "Overwrite Existing File", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);
                        if (num == JOptionPane.YES_OPTION) {
                            if (Resource.getInstance().dataDumpCSV(dump)) {
                                dbFilenameTF.setText("");
                                dbExportFolderTF.setText("");
                                JOptionPane.showMessageDialog(null, "Database successfully exported in CSV format.", "Export Database Succeed", JOptionPane.INFORMATION_MESSAGE);
                                expFrmtCB.setSelectedItem("CSV");
                                this.updateSystemProperties();
                            } else {
                                JOptionPane.showMessageDialog(null, "Could not export database!", "Export Database FAILED", JOptionPane.ERROR_MESSAGE);
                            }
                        }
                    } else {
                        if (Resource.getInstance().dataDumpCSV(dump)) {
                            dbFilenameTF.setText("");
                            dbExportFolderTF.setText("");
                            JOptionPane.showMessageDialog(null, "Database successfully exported in CSV format.", "Export Database Succeed", JOptionPane.INFORMATION_MESSAGE);
                            expFrmtCB.setSelectedItem("CSV");
                            this.updateSystemProperties();
                        } else {
                            JOptionPane.showMessageDialog(null, "Could not export database!", "Export Database FAILED", JOptionPane.ERROR_MESSAGE);
                        }
                    }
                } else if (expFrmtCB.getSelectedItem().equals("SQL")) {

                    dump = exportFolder + "/" + exportFile + ".sql";
                    if (new File(dump).exists()) {
                        //Wants to overwrite file... continue, else revert.
                        int num = JOptionPane.showConfirmDialog(null, "File: '" + dump + "' is currently available.\nDo you want to OVERWRITE it ?", "Overwrite Existing File", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);
                        if (num == JOptionPane.YES_OPTION) {
                            if (Resource.getInstance().dataDumpSQL(dump)) {
                                dbFilenameTF.setText("");
                                dbExportFolderTF.setText("");
                                JOptionPane.showMessageDialog(null, "Database successfully exported in SQL format.", "Export Database Succeed", JOptionPane.INFORMATION_MESSAGE);
                                expFrmtCB.setSelectedItem("SQL");
                                this.updateSystemProperties();
                            } else {
                                JOptionPane.showMessageDialog(null, "Could not export database!", "Export Database FAILED", JOptionPane.ERROR_MESSAGE);
                            }
                        }
                    } else {
                        if (Resource.getInstance().dataDumpSQL(dump)) {
                            dbFilenameTF.setText("");
                            dbExportFolderTF.setText("");
                            JOptionPane.showMessageDialog(null, "Database successfully exported in SQL format.", "Export Database Succeed", JOptionPane.INFORMATION_MESSAGE);
                            expFrmtCB.setSelectedItem("SQL");
                            this.updateSystemProperties();
                        } else {
                            JOptionPane.showMessageDialog(null, "Could not export database!", "Export Database FAILED", JOptionPane.ERROR_MESSAGE);
                        }
                    }
                } else {
                    JOptionPane.showMessageDialog(null, "Selected export option does not exists", "Invalid Export Option", JOptionPane.ERROR_MESSAGE);
                }
            } else {
                dbExportFolderTF.setText("");
                JOptionPane.showMessageDialog(null, "Please provide a valid export folder location for export !", "Invalid Folder", JOptionPane.WARNING_MESSAGE);
            }
        }
    }//GEN-LAST:event_jButton2ActionPerformed

    private void lockWinBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_lockWinBtnActionPerformed
        // TODO add your handling code here:
        doLockWindow();
    }//GEN-LAST:event_lockWinBtnActionPerformed

    private void enableLockItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_enableLockItemStateChanged
        // TODO add your handling code here:
        if (enableLock.isSelected()) {
            lockDownTF.setEnabled(true);
        }
        if (!enableLock.isSelected()) {
            lockDownTF.setEnabled(false);
        }
    }//GEN-LAST:event_enableLockItemStateChanged

    private void backupRBItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_backupRBItemStateChanged
        // TODO add your handling code here:
        if (backupRB.isSelected()) {
            //Decrypt backup files option
            detailsPane.removeAll();
            detailsPane.add(decryptBackupPane, BorderLayout.CENTER);
            decryptBackupPane.setVisible(true);
            detailsPane.setVisible(true);
            detailsPane.validate();
            detailsPane.repaint();
        }
    }//GEN-LAST:event_backupRBItemStateChanged

    private void ownRBItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_ownRBItemStateChanged
        // TODO add your handling code here:
        if (ownRB.isSelected()) {
            //Decrypt own files option
            //System.out.println("Showing decrypt own pane...");//Diagnostics
            detailsPane.removeAll();
            detailsPane.add(decryptOwnPane, BorderLayout.CENTER);
            decryptOwnPane.setVisible(true);
            detailsPane.validate();
            detailsPane.repaint();
        }
    }//GEN-LAST:event_ownRBItemStateChanged

    private void restoreRefreshBtn1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_restoreRefreshBtn1ActionPerformed
        // TODO add your handling code here:
        this.initBkFileTable();
    }//GEN-LAST:event_restoreRefreshBtn1ActionPerformed

    private void clearDecOwnBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_clearDecOwnBtnActionPerformed
        // TODO add your handling code here:
        decOwnFileTf.setText("");
        decOwnPwdTf.setText("");
        decOwnDelCB.setSelected(false);
    }//GEN-LAST:event_clearDecOwnBtnActionPerformed

    private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed
        // TODO add your handling code here:
        JFileChooser chooser = new JFileChooser();
        chooser.setDialogTitle("Select file for decryption");
        chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
        if (chooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
            decOwnFileTf.setText(chooser.getSelectedFile().toString());
        }
    }//GEN-LAST:event_jButton4ActionPerformed

    private void targetFolderBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_targetFolderBtnActionPerformed
        // TODO add your handling code here:
        JFileChooser chooser = new JFileChooser();
        chooser.setDialogTitle("Select folder for decrypted location");
        chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
        if (chooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
            decTargetFolderTf.setText(chooser.getSelectedFile().toString());
        }
}//GEN-LAST:event_targetFolderBtnActionPerformed

    private void decryptBkBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_decryptBkBtnActionPerformed
        // TODO add your handling code here:
        int selectedVal = bkFileTable1.getSelectedRow();
        if (selectedVal != -1) {
            String shortfile = (String) bkFileTable1.getValueAt(selectedVal, 0);
            String completefile = Resource.getInstance().getBk().getBkpath() + "/" + shortfile;
            String destinationdir = decTargetFolderTf.getText();
            String destinationfile = destinationdir + "/" + decTargetFileTf.getText() + ".sql";
            File temp = new File(completefile);
            File tdir = new File(destinationdir);
            File temp1 = new File(destinationfile);
            if (temp.exists()) {
                if (tdir.exists()) {
                    if (temp1.exists()) {
                        int num = JOptionPane.showConfirmDialog(null, "Destination File: '" + temp1 + "' is currently available.\nDo you want to OVERWRITE it ?", "Overwrite Existing File", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);
                        if (num == JOptionPane.YES_OPTION) {
                            if (tdir.canWrite()) {
                                if (doDecryptBackupFile(completefile, destinationfile, 0, null)) {//SUCCEED ! :D
                                    JOptionPane.showMessageDialog(null, "Decryption SUCCEED!\nDecrypted location: " + temp1, "Decryption Succeeded", JOptionPane.INFORMATION_MESSAGE);
                                } else {
                                    JOptionPane.showMessageDialog(null, "Decryption FAILED!\nPossible Errors:\n\u2022 Wrong password.\n\u2022 Not a PasswordStore encrypted backup file. ", "Decryption FAILED", JOptionPane.ERROR_MESSAGE);
                                }
                            } else {
                                JOptionPane.showMessageDialog(null, "Destination Folder: '" + tdir + "' cannot be accessed.\nPlease pick another destination folder with 'Write' permissions.", "Decryption FAILED", JOptionPane.ERROR_MESSAGE);
                            }
                        }
                    } else {
                        if (tdir.canWrite()) {
                            if (doDecryptBackupFile(completefile, destinationfile, 0, null)) {//SUCCEED ! :D
                                JOptionPane.showMessageDialog(null, "Decryption SUCCEED!\nDecrypted location: " + temp1, "Decryption Succeeded", JOptionPane.INFORMATION_MESSAGE);
                            } else {
                                JOptionPane.showMessageDialog(null, "Decryption FAILED!\nPossible Errors:\n\u2022 Wrong password.\n\u2022 Not a PasswordStore encrypted backup file. ", "Decryption FAILED", JOptionPane.ERROR_MESSAGE);
                            }
                        } else {
                            JOptionPane.showMessageDialog(null, "Destination Folder: '" + tdir + "' cannot be accessed.\nPlease pick another destination folder with 'Write' permissions.", "Decryption FAILED", JOptionPane.ERROR_MESSAGE);
                        }
                    }
                } else {
                    JOptionPane.showMessageDialog(null, "Destination folder: '" + tdir + "' does not exists !", "Decryption Destination Folder Not Found", JOptionPane.ERROR_MESSAGE);
                }
            } else {//backup file not existing
                JOptionPane.showMessageDialog(null, "Backup file: " + shortfile + " ,does not exists !", "Backup File Not Found", JOptionPane.ERROR_MESSAGE);
            }
        }
    }//GEN-LAST:event_decryptBkBtnActionPerformed

    private void decryptOwnBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_decryptOwnBtnActionPerformed
        // TODO add your handling code here:
        String completefile = decOwnFileTf.getText();
        String destinationdir = decTargetFolderTf.getText();
        String destinationfile = destinationdir + "/" + decTargetFileTf.getText() + ".sql";
        File temp = new File(completefile);
        File tdir = new File(destinationdir);
        File temp1 = new File(destinationfile);
        if (temp.exists()) {
            if (tdir.exists()) {
                if (temp1.exists()) {
                    int num = JOptionPane.showConfirmDialog(null, "Destination File: '" + temp1 + "' is currently available.\nDo you want to OVERWRITE it ?", "Overwrite Existing File", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);
                    if (num == JOptionPane.YES_OPTION) {
                        if (tdir.canWrite()) {
                            if (doDecryptBackupFile(completefile, destinationfile, 1, decOwnPwdTf.getPassword())) {
                                if (decOwnDelCB.isSelected()) {
                                    temp.delete();
                                }
                                JOptionPane.showMessageDialog(null, "Decryption SUCCEED!\nDecrypted location: " + temp1, "Decryption Succeeded", JOptionPane.INFORMATION_MESSAGE);
                            } else {
                                JOptionPane.showMessageDialog(null, "Decryption FAILED!\nPossible Errors:\n\u2022 Wrong password.\n\u2022 Not a PasswordStore encrypted backup file. ", "Decryption FAILED", JOptionPane.ERROR_MESSAGE);
                            }
                        } else {
                            JOptionPane.showMessageDialog(null, "Destination Folder: '" + tdir + "' cannot be accessed.\nPlease pick another destination folder with 'Write' permissions.", "Decryption FAILED", JOptionPane.ERROR_MESSAGE);
                        }
                    }
                } else {
                    if (tdir.canWrite()) {
                        if (doDecryptBackupFile(completefile, destinationfile, 1, decOwnPwdTf.getPassword())) {
                            if (decOwnDelCB.isSelected()) {
                                temp.delete();
                            }
                            JOptionPane.showMessageDialog(null, "Decryption SUCCEED!\nDecrypted location: " + temp1, "Decryption Succeeded", JOptionPane.INFORMATION_MESSAGE);
                        } else {
                            JOptionPane.showMessageDialog(null, "Decryption FAILED!\nPossible Errors:\n\u2022 Wrong password.\n\u2022 Not a PasswordStore encrypted backup file. ", "Decryption FAILED", JOptionPane.ERROR_MESSAGE);
                        }
                    } else {
                        JOptionPane.showMessageDialog(null, "Destination Folder: '" + tdir + "' cannot be accessed.\nPlease pick another destination folder with 'Write' permissions.", "Decryption FAILED", JOptionPane.ERROR_MESSAGE);
                    }
                }
            } else {
                JOptionPane.showMessageDialog(null, "Destination folder: '" + tdir + "' does not exists !", "Decryption Destination Folder Not Found", JOptionPane.ERROR_MESSAGE);
            }
        } else {//backup file not existing
            JOptionPane.showMessageDialog(null, "Backup file: " + temp + " ,does not exists !", "Backup File Not Found", JOptionPane.ERROR_MESSAGE);
        }
    }//GEN-LAST:event_decryptOwnBtnActionPerformed

    private void delBkBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_delBkBtnActionPerformed
        // TODO add your handling code here:
        doDeleteBackup();
    }//GEN-LAST:event_delBkBtnActionPerformed

    private void tableMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tableMouseClicked
        // TODO add your handling code here:
        if (evt.getClickCount() == 2) {
            setTableRow(table.rowAtPoint(evt.getPoint())); //Get pointer positioon on table
            int selectedRow = this.getTableRow();
            if (selectedRow != -1) {
                String username = (String) table.getValueAt(selectedRow, 0);
                int rqplaceNum = 1;
                if (this.isShowPassword()) {
                    rqplaceNum = 2;
                }
                String rqplace = (String) table.getValueAt(selectedRow, rqplaceNum);
                pass = new Password();
                pass.setUname(username);
                pass.setRplace(rqplace);
                String tempPass = Resource.getInstance().getSql().viewPassword(pass);
                pass.setUpass(tempPass);
                ViewPasswordDialog dialog = new ViewPasswordDialog(pass);
                dialog.setVisible(true);
                dialog.setLocationRelativeTo(this);
                dialog.setTitle("View Password");
                dialog.setIconImage(iconImg);
            }
        }
    }//GEN-LAST:event_tableMouseClicked

    private void fileBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_fileBtnActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_fileBtnActionPerformed

    private void importBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_importBtnActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_importBtnActionPerformed

    private void clearImpBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_clearImpBtnActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_clearImpBtnActionPerformed

    private void dbExportFolderTFActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_dbExportFolderTFActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_dbExportFolderTFActionPerformed

    private void quitBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_quitBtnActionPerformed
        // TODO add your handling code here:
        this.quitApp();
    }//GEN-LAST:event_quitBtnActionPerformed

    public void adjustSystem() {
        initSettingsPane();
        Resource.getInstance().getMainInstance().doLAF();
        this.validate();
        this.repaint();
    }

    public void addUniversalQuitBtn() {
        // Thanks to http://www.java-forums.org/awt-swing/12267-how-add-jbutton-tabbed-pane-headder.html forum post regarding adding a button on glasspane.
        Rectangle tabBounds = mainTabPane.getBoundsAt(0);
        Container glassPane = (Container) this.getRootPane().getGlassPane();
        glassPane.setVisible(true);
        glassPane.setLayout(new GridBagLayout());
        GridBagConstraints gbc = new GridBagConstraints();
        gbc.weightx = 1.0;
        gbc.weighty = 1.0;
        gbc.fill = GridBagConstraints.NONE;
        gbc.insets = new Insets(tabBounds.y, 0, 0, 10);
        gbc.anchor = GridBagConstraints.NORTHEAST;
        quitBtn.setPreferredSize(new Dimension(quitBtn.getPreferredSize().width, (int) tabBounds.getHeight() - 2));
        glassPane.add(quitBtn, gbc);

    }

    public void closeAppWindow() { // Attempts to close Window
//        System.out.println("MinOnClose: " + isMiniOnClose()); // Diagnostics
        if (isMiniOnClose()) {
            this.setVisible(false);
//            System.out.println("Now what"); //Diagnostic
        } else {
            quitApp();
        }

    }

    public void quitApp() { // Quits application
        Resource.getInstance().shutdown();
    }

    public void doLockWindow() {
        this.setVisible(false);
        if (addPassItem != null) {
            addPassItem.setEnabled(false);
        }
        Resource.getInstance().getMainInstance().setIsLocked(true);
        Resource.getInstance().getMainInstance().getLogin().setTitle("Unlock Window");
        Resource.getInstance().getSql().disconnectDB();
        Resource.getInstance().setPassword(new char[]{});
        Resource.getInstance().getMainInstance().getLogin().setVisible(true);
        Resource.getInstance().getMainInstance().getLogin().prepTextField();
    }

    public void doUnlockWindow() {
        Resource.getInstance().getMainInstance().setIsLocked(false);
        Resource.getInstance().getMainInstance().getLogin().setVisible(false);
        Resource.getInstance().getMainInstance().getLogin().setTitle("PasswordStore - Login");
        this.setVisible(true);
        for (int i = 0; i < invisibleDialogs.size(); i++) {
            String tmp = invisibleDialogs.get(i);

        }
        for (int i = 0; i < invisibleDialogs.size(); i++) {
            invisibleDialogs.remove(i);
        }
        if (addPassItem != null) {
            addPassItem.setEnabled(true);
        }
    }

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new MainFrame().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JPanel aboutTab;
    private javax.swing.JPanel backupPane;
    private javax.swing.JRadioButton backupRB;
    private javax.swing.JPanel backupTab;
    private javax.swing.JPanel bkBottomPane;
    private javax.swing.JButton bkBtn;
    private javax.swing.JTable bkFileTable;
    private javax.swing.JTable bkFileTable1;
    private javax.swing.JPanel bkPane;
    private javax.swing.ButtonGroup buttonGroup1;
    private javax.swing.JButton chgPwdBtn;
    private javax.swing.JLabel chgPwdLbl;
    private javax.swing.JPanel chgPwdPane;
    private javax.swing.JPasswordField chgPwdTf;
    private javax.swing.JButton clearClipBtn;
    private javax.swing.JButton clearDecOwnBtn;
    private javax.swing.JButton clearImpBtn;
    private javax.swing.JButton closeSearchBtn;
    private javax.swing.JPanel contentPane;
    private javax.swing.JMenuItem copyPassword;
    private javax.swing.JMenuItem copyRQ;
    private javax.swing.JMenuItem copyUsername;
    private javax.swing.JTextField dbExportFolderTF;
    private javax.swing.JTextField dbFilenameTF;
    private javax.swing.JTextField dbFilenameTF1;
    private javax.swing.JPanel decBkBtmPane;
    private javax.swing.JPanel decBkContPane;
    private javax.swing.JPanel decBkContTable;
    private javax.swing.JPanel decOwnBtmPane;
    private javax.swing.JPanel decOwnContPane;
    private javax.swing.JCheckBox decOwnDelCB;
    private javax.swing.JTextField decOwnFileTf;
    private javax.swing.JPasswordField decOwnPwdTf;
    private javax.swing.JTextField decTargetFileTf;
    private javax.swing.JTextField decTargetFolderTf;
    private javax.swing.JPanel decUpperPane;
    private javax.swing.JPanel decryptBackupPane;
    private javax.swing.JButton decryptBkBtn;
    private javax.swing.JButton decryptOwnBtn;
    private javax.swing.JPanel decryptOwnPane;
    private javax.swing.JPanel decryptPane;
    private javax.swing.JPanel decryptTab;
    private javax.swing.JButton delBkBtn;
    private javax.swing.JMenuItem delPwdBtn;
    private javax.swing.JPanel detailsPane;
    private javax.swing.JButton doSearchBtn;
    private javax.swing.JCheckBox enableLock;
    private javax.swing.JComboBox expFrmtCB;
    private javax.swing.JPanel exportPane;
    private javax.swing.JPanel exportPanel;
    private javax.swing.JPanel exportTab;
    private javax.swing.JButton fileBtn;
    private javax.swing.JPanel generalPane;
    private javax.swing.JPanel generalTab;
    private javax.swing.JButton importBtn;
    private javax.swing.JPanel importPanel;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton4;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel17;
    private javax.swing.JLabel jLabel18;
    private javax.swing.JLabel jLabel19;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel20;
    private javax.swing.JLabel jLabel21;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane4;
    private javax.swing.JScrollPane jScrollPane5;
    private javax.swing.JScrollPane jScrollPane6;
    private javax.swing.JTextArea jTextArea1;
    private javax.swing.JTextArea jTextArea2;
    private javax.swing.JComboBox lafCB;
    private javax.swing.JTextField lockDownTF;
    private javax.swing.JCheckBox lockOnMinCB;
    private javax.swing.JButton lockWinBtn;
    private javax.swing.JTabbedPane mainTabPane;
    private javax.swing.JCheckBox minWindow;
    private javax.swing.JButton newBtn;
    private javax.swing.JRadioButton ownRB;
    private javax.swing.JPanel passwordTab;
    private javax.swing.JPopupMenu popup;
    private javax.swing.JButton quitBtn;
    private javax.swing.JButton refreshBtn;
    private javax.swing.JPanel restorePane;
    private javax.swing.JPanel restorePanel;
    private javax.swing.JButton restoreRefreshBtn;
    private javax.swing.JButton restoreRefreshBtn1;
    private javax.swing.JButton restoreSelectBtn;
    private javax.swing.JButton saveGenSetBtn;
    private javax.swing.JScrollPane scroll;
    private javax.swing.JButton searchBtn;
    private javax.swing.JLabel searchLbl;
    private javax.swing.JPanel searchLeftPane;
    private javax.swing.JPanel searchPane;
    private javax.swing.JPanel searchRightPane;
    private javax.swing.JTextField searchTf;
    private javax.swing.JPanel settingsTab;
    private javax.swing.JTabbedPane settingsTabPane;
    private javax.swing.JTable table;
    private javax.swing.JButton targetFolderBtn;
    private javax.swing.JButton termAcctBtn;
    private javax.swing.JPanel tmAcctPane;
    private javax.swing.JToolBar toolbar;
    private javax.swing.JPanel toolsTab;
    private javax.swing.JTabbedPane toolsTabPane;
    private javax.swing.JPanel userAccountTab;
    private javax.swing.JMenuItem viewPwdBtn;
    private javax.swing.JCheckBox viewTable;
    // End of variables declaration//GEN-END:variables
}
